// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
import App from './App.vue'
import {
  $http
} from '@escook/request-miniprogram'
import {
  createPinia
} from 'pinia'

// 全局配置
const app = createSSRApp(App)
const pinia = createPinia()
app.use(pinia)
// HTTP请求配置
uni.$http = $http
$http.baseUrl = process.env.NODE_ENV === 'development' ?
  'http://localhost:8090' :
  'https://cdcas.com'

// 请求拦截器
$http.beforeRequest = function(options) {
  options.header = {
    authorization: "Bearer " + uni.getStorageSync('token'),
    id: uni.getStorageSync('userInfo')?._id || ''
  }
}

// 响应拦截器
$http.afterRequest = function() {
  setTimeout(() => uni.hideLoading(), 800)
}

// 全局方法
uni.$showMsg = function(title = '数据加载失败', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none'
  })
}

export function createApp() {
  return {
    app,
    pinia
  }
}
// #endif